package com.umeox.watch.moto.launcher.utils;


import android.util.Log;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;

public class Utils {
    /**
     * 获取12小时制格式
     *
     * @param time   10:00、23:22格式
     * @param locale
     * @return 返回 10:00、11:22格式
     */
    public static String to12HourFormat(String time, Locale locale) {
        try {
            SimpleDateFormat hourFormat = new SimpleDateFormat("hh:mm", locale);
            return hourFormat.format(hourFormat.parse(time));
        } catch (ParseException e) {
            Log.e("DATEUTILS", "to12HourFormat: ", e);
        }
        return time;
    }

    public static String to24HourFormat(String time, Locale locale) {
        try {
            SimpleDateFormat hourFormat = new SimpleDateFormat("HH:mm", locale);
            return hourFormat.format(hourFormat.parse(time));
        } catch (ParseException e) {
            Log.e("DATEUTILS", "to24HourFormat: ", e);
        }
        return time;
    }
}
